package com.itheima.utils;



import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtils {
    private static final String JWT_SECRET = "itheima";
    private static final long JWT_TTL = 60 * 60 * 1000;
    public static String createJwt(Map<String,Object>  claims){
        return Jwts.builder().setClaims( claims)
                .signWith(SignatureAlgorithm.HS512, JWT_SECRET)
                .setExpiration(new Date(System.currentTimeMillis() + JWT_TTL))
                .compact();
    }
    public static Map<String,Object> parseJwt(String  token){
        Claims body=null;
        try {
             body = Jwts.parser()
                    .setSigningKey(JWT_SECRET)
                    .parseClaimsJws(token)
                    .getBody();
        } catch (Exception e) {
        }
        return body;
    }
}
